﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaccaratRally.DataKernel.Entity;
using BaccaratRally.DataKernel.Service;

namespace BaccaratRally.Service
{
    public partial class Status : System.Web.UI.Page
    {
        public string AccountName;

        protected void Page_Load(object sender, EventArgs e)
        {
            AccountName = Request.QueryString["a"];

            AccountService aservice = ServiceFactory.CreateService<AccountService>();
            List<Account> accountlist = aservice.GetAccount(AccountName);

            lbStatusA.Text = accountlist[0].CurrSite + " [" + accountlist[0].IPAddress + "] " + ((accountlist[0].Online == 1) && (accountlist[0].LastActive.AddMinutes(3) > DateTime.Now) ? "在线" : "离线") + " 最后活动时间:" + accountlist[0].LastActive.ToString("yyyy-MM-dd HH:mm:ss");
            lbStatusB.Text = accountlist[1].CurrSite + " [" + accountlist[1].IPAddress + "] " + ((accountlist[1].Online == 1) && (accountlist[1].LastActive.AddMinutes(3) > DateTime.Now)  ? "在线" : "离线") + " 最后活动时间:" + accountlist[1].LastActive.ToString("yyyy-MM-dd HH:mm:ss");
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            if (this.txbHours.Text != "")
            {
                AccountName = Request.QueryString["a"];

                BetItemService bis = ServiceFactory.CreateService<BetItemService>();
                List<BetItem> bl = bis.GetBetItemList(AccountName, int.Parse(this.txbHours.Text));

                lbSumA.Text = "流水:" + (from l in bl where l.AccountPos == "A" select l.BetSize).Sum().ToString() + " 有效流水:" + (from l in bl where l.AccountPos == "A" && l.BetResult != "D" select l.BetSize).Sum().ToString()
                    + " 盈利:" + (from l in bl where l.AccountPos == "A" select l.BetProfit).Sum().ToString();
                lbSumB.Text = "流水:" + (from l in bl where l.AccountPos == "B" select l.BetSize).Sum().ToString() + " 有效流水:" + (from l in bl where l.AccountPos == "B" && l.BetResult != "D" select l.BetSize).Sum().ToString()
                    + " 盈利:" + (from l in bl where l.AccountPos == "B" select l.BetProfit).Sum().ToString();
            }

        }
    }
}